import request from "@/utils/request";
import {getToken} from "@/utils/auth";
import qs from 'qs'



var axios = require('axios');

// axios(config)
//     .then(function (response) {
//         console.log(JSON.stringify(response.data));
//     })
//     .catch(function (error) {
//         console.log(error);
//     });

export function deleteAgrPro(id) {
    let data = {
        id:id
    }
    return request({
        url: `/jeecg-boot/agrwf/agrProjects/delete`,
        method: 'DELECT',
        headers:{
            isToken:true,
            'X-Access-Token':getToken()
        },
        data:qs.stringify(data)
    })
}


export function idQueryAppendix(id) {
    return request({
        url: `/jeecg-boot/agr/agrProjects/queryApDocumentsByMainId?id=${id}`,
        method: 'get',
        headers:{
            isToken:true,
            'X-Access-Token':getToken()
        },
    })
}

export function editForm(form) {
    var data = JSON.stringify({
        "apAddress": form.apAddress,
        "apAgrotype": Number(form.apAgrotype),
        "apApproveDate": form.apApproveDate,
        "apApproveOpinions": form.apApproveOpinions,
        "apApproveUser": "",
        "apArea": form.apArea[2],
        "apBeginDate": "",
        "apBorderPic": "",
        "apBorderTxt": form.apBorderTxt,
        "apCode": form.apCode,
        "apCompleteDate": "",
        "apConfirmDate": "",
        "apConfirmOpinions": "",
        "apCost": 0,
        "apDesc": form.apDesc,
        "apDisasterType": Number(form.apDisasterType),
        "apStartDate": form.apStartDate,
        "apTecDate": "",
        "apTecOpinions": "",
        "apTecUser": "",
        "apType": Number(form.apType),
        "approveText": "",
        "createBy": "",
        "createTime": "",
        "id": "",
        "sysOrgCode": "",
        "updateBy": "",
        "updateTime": "",
        "apName": form.apName,
        "apStatus": Number(form.apStatus),
        "apLinkMan": form.apLinkMan,
        "apLinkTelephone": form.apLinkTelephone,
        "apEndDate": form.apEndDate
    });
    console.log(data)
    var config = {
        method: 'post',
        url: '/jeecg-boot/agrwf/agrProjects/edit',
        headers: {
            'X-Access-Token': getToken(),
            'Content-Type': 'application/json'
        },
        data : data
    };
    return request(config)
}

export function saveForm(form) {
    var data = JSON.stringify({
        "apAddress": form.apAddress,
        "apAgrotype": Number(form.apAgrotype),
        "apApproveDate": form.apApproveDate,
        "apApproveOpinions": form.apApproveOpinions,
        "apApproveUser": "",
        "apArea": form.apArea[2],
        "apBeginDate": "",
        "apBorderPic": "",
        "apBorderTxt": form.apBorderTxt,
        "apCode": form.apCode,
        "apCompleteDate": "",
        "apConfirmDate": "",
        "apConfirmOpinions": "",
        "apCost": 0,
        "apDesc": form.apDesc,
        "apDisasterType": Number(form.apDisasterType),
        "apStartDate": form.apStartDate,
        "apTecDate": "",
        "apTecOpinions": "",
        "apTecUser": "",
        "apType": Number(form.apType),
        "approveText": "",
        "createBy": "",
        "createTime": "",
        "id": "",
        "sysOrgCode": "",
        "updateBy": "",
        "updateTime": "",
        "apName": form.apName,
        "apStatus": Number(form.apStatus) ,
        "apLinkMan": form.apLinkMan,
        "apLinkTelephone": form.apLinkTelephone,
        "apEndDate": form.apEndDate
    });
    console.log(data)
    var config = {
        method: 'post',
        url: '/jeecg-boot/agrwf/agrProjects/add',
        headers: {
            'X-Access-Token': getToken(),
            'Content-Type': 'application/json'
        },
        data : data
    };
    return request(config)
}



export function submitInfo(form){
    var config = {
        method: 'post',
        url: '/jeecg-boot/agrwf/agrProjects/approve',
        headers: {
            'X-Access-Token': getToken(),
            'Content-Type': 'application/json'
        },
        data : form
    };
    return request(config)
}

export function submitForm(id) {
    var data = JSON.stringify({
        "approveText": "",
        "id": id,
        "apStatus": 10
    });
    console.log(data)
    var config = {
        method: 'post',
        url: '/jeecg-boot/agrwf/agrProjects/approve',
        headers: {
            'X-Access-Token': getToken(),
            'Content-Type': 'application/json'
        },
        data : data
    };
    return request(config)
}
